package cn.tmall.cmm.impl;

import cn.tmall.IArticleService;
import cn.tmall.commons.enums.cms.ChannelEnum;
import cn.tmall.commons.service.impl.BaseServiceImpl;
import cn.tmall.commons.utils.factory.Page;
import cn.tmall.dao.cms.ArticleRepository;
import cn.tmall.entity.cms.Article;
import cn.tmall.query.SearchFilter;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.List;

/**
 * @author YANG
 */
@Service
public class ArticleServiceImpl extends BaseServiceImpl<Article, Long, ArticleRepository> implements IArticleService {

    @Autowired
    @Qualifier("articleRepository")
    private ArticleRepository articleRepository;

    /**
     * 查询首页最近5条资讯数据
     *
     * @return
     */
    @Override
    public List<Article> queryIndexNews() {
        Page<Article> page = query(1, 5, ChannelEnum.NEWS.getId());
        return page.getRecords();
    }

    @Override
    public Page<Article> query(int currentPage, int size, Long idChannel) {
        Page page = new Page(currentPage, size, "id");
        page.addFilter(SearchFilter.build("idChannel", SearchFilter.Operator.EQ, idChannel));
        return queryPage(page);

    }
}
